package com.yunduo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunduo.common.YunDuoConst.AdminParam;
import com.yunduo.entity.Log;
import com.yunduo.mapper.LogMapper;
import com.yunduo.service.LogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统日志服务
 */
@Service("logService")
public class LogServiceImpl extends ServiceImpl<LogMapper, Log> implements LogService {
    @Resource
    private LogMapper logMapper;


    @Override
    public List<Log> getRolesByIds(String event, Integer count) {
        List<Log> logs = logMapper.selectUserLoginLog(event, count);
        return logs;
    }

    @Override
    public List<String> getLogByName(String name) {
        return logMapper.selectLogByName(name);
    }

    @Override
    public Log getLogByEventAndResult(String event, String result) {
        return logMapper.selectLogByEventAndResult(event,result);
    }

    @Override
    public boolean removeLogByEventAndResult(String event, String result) {
        return logMapper.deleteLogByEventAndResult(event,result);
    }

    @Override
    public boolean updateEmailByUserId(String userId, String email) {
        LambdaQueryWrapper<Log> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Log::getEvent, AdminParam.USEREMAILEVENT+","+userId);
        Log userEmail = this.getOne(queryWrapper);
        userEmail.setResult(email);
        this.updateById(userEmail);
        return true;
    }
}
